﻿using System;
using System.Collections.Generic;

namespace Hxsoft.AppV1.Module
{
	/// <summary>
	/// 站点基本信息类。
	/// </summary>
	/// <remarks>通协定的 Hxsoft.AppV1.WebUI.BaseInfoService 服务来实现不同站点的相互通讯。</remarks>
	public static class SiteBaseInfo
	{
		/// <summary>
		/// 静态存储站点部署的路径。
		/// </summary>
		private static Dictionary<int, string> siteApplicationPathDictionary;
		/// <summary>
		/// 静态存储站点部署的路径。
		/// </summary>
		private static Dictionary<int, string> SiteApplicationPathDictionary
		{
			get
			{
				if (siteApplicationPathDictionary == null)
					siteApplicationPathDictionary = new Dictionary<int, string>();
				return siteApplicationPathDictionary;
			}
		}

		/// <summary>
		/// 获取站点应用的部署路径。
		/// </summary>
		/// <param name="siteId">站点的标识。</param>
		/// <returns>站点应用的部署路径。</returns>
		public static string GetSiteApplicationPath(int siteId)
		{
			if (SiteApplicationPathDictionary.ContainsKey(siteId))
				return SiteApplicationPathDictionary[siteId];

			string path = null;
			Site site = Sites.GetItem(siteId);
			if (site != null)
			{
				string url = site.MainDomain;
				if (!string.IsNullOrEmpty(url))
				{
					try
					{
						cn.com.sinoinfo.BaseInfoService service = new Hxsoft.AppV1.Module.cn.com.sinoinfo.BaseInfoService();
						url = "http://" + url + "/WebServices/BaseInfoService.asmx";
						service.Url = url;
						path = service.GetApplicationPath();
					}
					catch (Exception err)
					{
					}
				}
			}

			SiteApplicationPathDictionary[siteId] = path;
			return path;
		}





		/// <summary>
		/// 静态存储站点Google Maps的路径。
		/// </summary>
		private static Dictionary<int, string> siteGMapUrlDictionary;
		/// <summary>
		/// 静态存储站点Google Maps的路径。
		/// </summary>
		private static Dictionary<int, string> SiteGMapUrlDictionary
		{
			get
			{
				if (siteGMapUrlDictionary == null)
					siteGMapUrlDictionary = new Dictionary<int, string>();
				return siteGMapUrlDictionary;
			}
		}

		/// <summary>
		/// 获取站点Google Maps的路径。
		/// </summary>
		/// <param name="siteId">站点的标识。</param>
		/// <returns>站点Google Maps的路径。</returns>
		public static string GetSiteGMapUrl(int siteId)
		{
			if (SiteGMapUrlDictionary.ContainsKey(siteId))
				return SiteGMapUrlDictionary[siteId];

			string mapUrl = null;
			Site site = Sites.GetItem(siteId);
			if (site != null)
			{
				string url = site.MainDomain;
				if (!string.IsNullOrEmpty(url))
				{
					try
					{
						cn.com.sinoinfo.BaseInfoService service = new Hxsoft.AppV1.Module.cn.com.sinoinfo.BaseInfoService();
						url = "http://" + url + "/WebServices/BaseInfoService.asmx";
						service.Url = url;
						mapUrl = service.GetGMapUrl();
					}
					catch (Exception err)
					{
					}
				}
			}

			SiteGMapUrlDictionary[siteId] = mapUrl;
			return mapUrl;
		}
	}
}